import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/Qadd',
    component: () => import('@/views/phone/QualityAdd'),
    hidden: true
  },
  {
    path: '/res',
    component: () => import('@/views/login/components/ResultSearch'),
    hidden: true
  },
  {
    path: '/trace',
    component: () => import('@/views/login/components/TraceByCode'),
    hidden: true
  },
  {
    path: '/begins',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/ProductSearch'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
//质检员管理
//   {
//     // 物流用户可见
//     path: '/QualityUser',
//     component: Layout,
//     redirect: '/permission/page',
//     alwaysShow: true, // will always show the root menu
//     name: 'QualityUser',
//     meta: {
//       title: '企业质检员管理',
//       icon: 'el-icon-suitcase-1',
//       roles: ['firmus', 'admin'] // you can set roles in root nav
//     },
//     children: [
//       {
//         path: 'QualityUser',
//         component: () => import('@/views/business-management/enterprise-management/QualityUser/QualityUser'),
//         name: 'QualityUser',
//         meta: {
//           title: '质检员管理',
//           icon: 'el-icon-s-home',
//           roles: ['firmus', 'admin'] // or you can only set roles in sub nav
//         }
//       },
//       {
//         path: 'QuChart',
//         component: () => import('@/views/business-management/enterprise-management/QualityUser/QuChart'),
//         name: 'QuChart',
//         meta: {
//           title: '质检人员数据可视化',
//           icon: 'el-icon-s-home',
//           roles: ['firmus', 'admin'] // or you can only set roles in sub nav
//         }
//       },]
//   },

  {
    // 人员管理
    path: '/user-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'User-management',
    meta: {
      title: '人员管理',
      icon: 'el-icon-user',
      roles: ['farmus','firmus','transp','market'] // you can set roles in root nav
    },
    children: [
      {
        path: 'UserEchat',
        component: () => import('@/views/user-management/UserEchat'),
        name: 'UserEchat',
        meta: {
          title: '数据可视化',
          roles: ['admin']
        }
      },
      {
        path: 'userIndex',
        component: () => import('@/views/user-management/UserIndex'),
        name: 'UserIndex',
        meta: {
          title: '人员管理',
          roles: ['admin']
        }
      },
      {
        path: 'UserFarmIndex',
        component: () => import('@/views/user-management/UserFarmIndex'),
        name: 'UserFarmIndex',
        meta: {
          title: '个人信息管理',
          roles: ['farmus']
        }
      },
      {
        path: 'UserFirmIndex',
        component: () => import('@/views/user-management/UserFirmIndex'),
        name: 'UserFirmIndex',
        meta: {
          title: '个人信息管理',
          roles: ['firmus']
        }
      },
      {
        path: 'UserTronspIndex',
        component: () => import('@/views/user-management/UserTronspIndex'),
        name: 'UserTronspIndex',
        meta: {
          title: '个人信息管理',
          roles: ['transp']
        }
      },
      {
        path: 'UserMarketIndex',
        component: () => import('@/views/user-management/UserMarketIndex'),
        name: 'UserMarketIndex',
        meta: {
          title: '个人信息管理',
          roles: ['market']
        }
      }
    ],





  },
  {

    // 超市用户可见
    path: '/store-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Store-management',
    meta: {
      title: '超市管理模块',
      icon: 'el-icon-suitcase-1',
      roles: [ 'market'] // you can set roles in root nav
    },
    children: [{
      path: 'commodityManagement',
      component: () => import('@/views/business-management/store-management/CommodityManagement.vue'),
      name: 'CommodityManagement',
      meta: {
        title: '超市商品信息管理',
        icon: 'el-icon-shopping-cart-full',
        roles: ['admin', 'market']
      }
    },
    {
      path: 'enterpriseManagement',
      component: () => import('@/views/business-management/store-management/EnterpriseManagement.vue'),
      name: 'EnterpriseManagement',
      meta: {
        title: '生产企业管理',
        icon: 'tree',
        roles: ['admin', 'market'] // or you can only set roles in sub nav
      }
    },
    {
      path: 'chart',
      component: () => import('@/views/business-management/store-management/StChart.vue'),
      name: 'StChart',
      meta: {
        title: '数据可视化',
        icon: 'table',
        roles: ['admin', 'market'] // or you can only set roles in sub nav
      }
    }
    ]
  },
  {
    // 企业用户可见
    path: '/enterprise-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Enterprise-management',
    meta: {
      title: '生产企业管理模块',
      icon: 'el-icon-suitcase-1',
      roles: ['firmus'] // you can set roles in root nav
    },
    children: [{
      path: 'productLogistics',
      component: () => import('@/views/business-management/enterprise-management/ProductLogistics.vue'),
      name: 'ProductLogistics',
      meta: {
        title: '产品物流管理',
        icon: 'el-icon-truck',
        roles: ['firmus', 'admin']
      }
    },
    {
      path: 'FarmManagement',
      component: () => import('@/views/business-management/enterprise-management/FarmManagement.vue'),
      name: 'FarmManagement',
      meta: {
        title: '供货农场管理',
        icon: 'el-icon-s-home',
        roles: ['firmus', 'admin'] // or you can only set roles in sub nav
      }
    },
    {
      path: 'feedbackManagement',
      component: () => import('@/views/business-management/enterprise-management/FeedbackManagement.vue'),
      name: 'FeedbackManagement',
      meta: {
        icon: 'form',
        title: '反馈信息管理',
        roles: ['firmus', 'admin']
        // if do not set roles, means: this page does not require permission
      }
    },
    {
      path: 'productInfoManagement',
      component: () => import('@/views/business-management/enterprise-management/ProductInfoManagement.vue'),
      name: 'ProductInfoManagement',
      meta: {
        icon: 'el-icon-s-goods',
        title: '企业生产产品管理'
        // if do not set roles, means: this page does not require permission
      }
    },
    {
      path: 'cooperativeLog',
      component: () => import('@/views/business-management/enterprise-management/CooperativeLog.vue'),
      name: 'CooperativeLog',
      meta: {
        icon: 'el-icon-bicycle',
        title: '合作物流公司管理'
        // if do not set roles, means: this page does not require permission
      }
    },
    {
      path: 'chart',
      component: () => import('@/views/business-management/enterprise-management/EnChart.vue'),
      name: 'EnChart',
      meta: {
        title: '数据可视化',
        icon: 'table',
        roles: ['admin', 'firmus'] // or you can only set roles in sub nav
      }
    },
]
  },
  {
    // 物流用户可见
    path: '/logistics-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Logistics-management',
    meta: {
      title: '物流公司管理模块',
      icon: 'el-icon-suitcase-1',
      roles: ['transp', 'admin'] // you can set roles in root nav
    },
    children: [{
      path: 'transportationManagement',
      component: () => import('@/views/business-management/logistics-management/TransportationManagement.vue'),
      name: 'TransportationManagement',
      meta: {
        title: '物流承包管理',
        icon: 'el-icon-ship',
        roles: ['transp', 'admin'] // or you can only set roles in sub nav
      }
    },
    {
      path: 'LoChart',
      component: () => import('@/views/business-management/logistics-management/LoChart.vue'),
      name: 'LoChart',
      meta: {
        title: '可视化',
        icon: 'el-icon-house',
        roles: ['transp', 'admin'] // or you can only set roles in sub nav
      }
    },
      {
        path: 'cooperativeFarm',
        component: () => import('@/views/business-management/logistics-management/CooperativeFarm.vue'),
        name: 'CooperativeFarm',
        meta: {
          title: '物流合作农场管理',
          icon: 'el-icon-house',
          roles: ['transp', 'admin'] // or you can only set roles in sub nav
        }
      },
    {
      path: 'chart',
      component: () => import('@/views/business-management/logistics-management/LoChart.vue'),
      name: 'LoChart',
      meta: {
        title: '数据可视化',
        icon: 'table',
        roles: ['admin', 'market'] // or you can only set roles in sub nav
      }
    }]
  },
  {
    // 农场用户可见
    path: '/farm-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Farm-management',
    meta: {
      title: '农场管理模块',
      icon: 'el-icon-suitcase-1',
      roles: ['farmus', 'admin'] // you can set roles in root nav
    },
    children: [{
      path: 'cooperativeEnt',
      component: () => import('@/views/business-management/farm-management/CooperativeEnt.vue'),
      name: 'CooperativeEnt',
      meta: {
        title: '农场合作企业管理',
        icon: 'el-icon-office-building',
        roles: ['farmus', 'admin'] // or you can only set roles in sub nav
      }
    }, {
      path: 'farmPro',
      component: () => import('@/views/business-management/farm-management/FarmPro.vue'),
      name: 'FarmPro',
      meta: {
        title: '农产品信息管理',
        icon: 'el-icon-grape',
        roles: ['farmus', 'admin'] // or you can only set roles in sub nav
      }
    },{
      path: 'FaChart',
      component: () => import('@/views/business-management/farm-management/FaChart.vue'),
      name: 'FaChart',
      meta: {
        title: '农产品信息可视化',
        icon: 'el-icon-grape',
        roles: ['farmus'] // or you can only set roles in sub nav
      }
    },
    {
      path: 'chart',
      component: () => import('@/views/business-management/farm-management/FaChart.vue'),
      name: 'FaChart',
      meta: {
        title: '数据可视化',
        icon: 'table',
        roles: ['admin', 'market'] // or you can only set roles in sub nav
      }
    }]
  },





  {
    // 人员管理
    path: '/business-management-surper/user-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'User-management',
    meta: {
      title: '人员管理',
      icon: 'el-icon-user',
      roles: ['surper'] // you can set roles in root nav
    },
    children: [
      {
        path: 'UserEchat',
        component: () => import('@/views/business-management-surper/user-management/UserEchat'),
        name: 'UserEchat',
        meta: {
          title: '数据可视化',
          roles: ['surper']
        }
      },
      {
        path: 'userIndex',
        component: () => import('@/views/business-management-surper/user-management/UserIndex'),
        name: 'UserIndex',
        meta: {
          title: '人员管理',
          roles: ['surper']
        }
      },
      {
        path: 'userPresentation',
        component: () => import('@/views/business-management-surper/user-management/userPresentation'),
        name: 'userPresentation',
        meta: {
          title: '权限介绍',
          roles: ['surper']
        }
      },
      {
        path: 'UserFirmIndex',
        component: () => import('@/views/user-management/UserFirmIndex'),
        name: 'UserFirmIndex',
        meta: {
          title: '个人信息管理',
          roles: ['firmus']
        }
      },
      {
        path: 'UserTronspIndex',
        component: () => import('@/views/user-management/UserTronspIndex'),
        name: 'UserTronspIndex',
        meta: {
          title: '个人信息管理',
          roles: ['transp']
        }
      },
      {
        path: 'UserMarketIndex',
        component: () => import('@/views/user-management/UserMarketIndex'),
        name: 'UserMarketIndex',
        meta: {
          title: '个人信息管理',
          roles: ['market']
        }
      },
      {
        path: 'UserFarmIndex',
        component: () => import('@/views/user-management/UserFarmIndex'),
        name: 'UserFarmIndex',
        meta: {
          title: '个人信息管理',
          roles: ['farmus']
        }
      }
    ],

  },
  {

    // 超市用户可见
    path: '/business-management-surper/store-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Store-management',
    meta: {
      title: '超市管理模块',
      icon: 'el-icon-suitcase-1',
      roles: [ 'surper'] // you can set roles in root nav
    },
    children: [{
      path: 'commodityManagement',
      component: () => import('@/views/business-management-surper/store-management/CommodityManagement.vue'),
      name: 'CommodityManagement',
      meta: {
        title: '超市商品信息管理',
        icon: 'el-icon-shopping-cart-full',
        //roles: ['admin', 'market']
      }
    },
      {
        path: 'enterpriseManagement',
        component: () => import('@/views/business-management-surper/store-management/EnterpriseManagement.vue'),
        name: 'EnterpriseManagement',
        meta: {
          title: '生产企业管理',
          icon: 'tree',
         // roles: ['admin', 'market'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'chart',
        component: () => import('@/views/business-management-surper/store-management/StChart.vue'),
        name: 'StChart',
        meta: {
          title: '数据可视化',
          icon: 'table',
         // roles: ['admin', 'market'] // or you can only set roles in sub nav
        }
      }
    ]
  },
  {
    // 企业用户可见
    path: '/business-management-surper/enterprise-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Enterprise-management',
    meta: {
      title: '生产企业管理模块',
      icon: 'el-icon-suitcase-1',
    roles: ['surper'] // you can set roles in root nav
    },
    children: [{
      path: 'productLogistics',
      component: () => import('@/views/business-management-surper/enterprise-management/ProductLogistics.vue'),
      name: 'ProductLogistics',
      meta: {
        title: '产品物流管理',
        icon: 'el-icon-truck',
       // roles: ['firmus', 'admin']
      }
    },
      {
        path: 'FarmManagement',
        component: () => import('@/views/business-management-surper/enterprise-management/FarmManagement.vue'),
        name: 'FarmManagement',
        meta: {
          title: '供货农场管理',
          icon: 'el-icon-s-home',
          //roles: ['firmus', 'admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'feedbackManagement',
        component: () => import('@/views/business-management-surper/enterprise-management/FeedbackManagement.vue'),
        name: 'FeedbackManagement',
        meta: {
          icon: 'form',
          title: '反馈信息管理',
       //   roles: ['firmus', 'admin']
          // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'productInfoManagement',
        component: () => import('@/views/business-management-surper/enterprise-management/ProductInfoManagement.vue'),
        name: 'ProductInfoManagement',
        meta: {
          icon: 'el-icon-s-goods',
          title: '企业生产产品管理'
          // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'cooperativeLog',
        component: () => import('@/views/business-management-surper/enterprise-management/CooperativeLog.vue'),
        name: 'CooperativeLog',
        meta: {
          icon: 'el-icon-bicycle',
          title: '合作物流公司管理'
          // if do not set roles, means: this page does not require permission
        }
      },
      {
        path: 'chart',
        component: () => import('@/views/business-management-surper/enterprise-management/EnChart.vue'),
        name: 'EnChart',
        meta: {
          title: '数据可视化',
          icon: 'table',
        //  roles: ['admin', 'firmus'] // or you can only set roles in sub nav
        }
      }]
  },
  {
    // 物流用户可见
    path: '/logistics-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Logistics-management',
    meta: {
      title: '物流公司管理模块',
      icon: 'el-icon-suitcase-1',
    roles: ['surper'] // you can set roles in root nav
    },
    children: [{
      path: 'transportationManagement',
      component: () => import('@/views/business-management-surper/logistics-management/TransportationManagement.vue'),
      name: 'TransportationManagement',
      meta: {
        title: '物流承包管理',
        icon: 'el-icon-ship',
     //   roles: ['transp', 'admin'] // or you can only set roles in sub nav
      }
    },
      {
        path: 'LoChart',
        component: () => import('@/views/business-management-surper/logistics-management/LoChart.vue'),
        name: 'LoChart',
        meta: {
          title: '可视化',
          icon: 'el-icon-house',
        //  roles: ['transp', 'admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'cooperativeFarm',
        component: () => import('@/views/business-management-surper/logistics-management/CooperativeFarm.vue'),
        name: 'CooperativeFarm',
        meta: {
          title: '物流合作农场管理',
          icon: 'el-icon-house',
         // roles: ['transp', 'admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'chart',
        component: () => import('@/views/business-management-surper/logistics-management/LoChart.vue'),
        name: 'LoChart',
        meta: {
          title: '数据可视化',
          icon: 'table',
       //   roles: ['admin', 'market'] // or you can only set roles in sub nav
        }
      }]
  },
  {
    // 农场用户可见
    path: '/farm-management',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Farm-management',
    meta: {
      title: '农场管理模块',
      icon: 'el-icon-suitcase-1',
      roles: ['surper'] // you can set roles in root nav
    },
    children: [{
      path: 'cooperativeEnt',
      component: () => import('@/views/business-management-surper/farm-management/CooperativeEnt.vue'),
      name: 'CooperativeEnt',
      meta: {
        title: '农场合作企业管理',
        icon: 'el-icon-office-building',
        //roles: ['farmus', 'admin'] // or you can only set roles in sub nav
      }
    }, {
      path: 'farmPro',
      component: () => import('@/views/business-management-surper/farm-management/FarmPro.vue'),
      name: 'FarmPro',
      meta: {
        title: '农产品信息管理',
        icon: 'el-icon-grape',
        //roles: ['farmus', 'admin'] // or you can only set roles in sub nav
      }
    },{
      path: 'FaChart',
      component: () => import('@/views/business-management-surper/farm-management/FaChart.vue'),
      name: 'FaChart',
      meta: {
        title: '农产品信息可视化',
        icon: 'el-icon-grape',
       // roles: ['farmus'] // or you can only set roles in sub nav
      }
    },
      {
        path: 'chart',
        component: () => import('@/views/business-management-surper/farm-management/FaChart.vue'),
        name: 'FaChart',
        meta: {
          title: '数据可视化',
          icon: 'table',
        //  roles: ['admin', 'market'] // or you can only set roles in sub nav
        }
      }]
  },


  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()


export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
